package com.zjl.litemall.admin.controller;

import com.zjl.litemall.core.util.ResponseUtil;
import com.zjl.litemall.db.service.LitemallGoodsProductService;
import com.zjl.litemall.db.service.LitemallGoodsService;
import com.zjl.litemall.db.service.LitemallOrderService;
import com.zjl.litemall.db.service.LitemallUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.logging.log4j.LogManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author cat
 * @description
 * @date 2022/2/25 下午10:24
 */

@RestController
@RequestMapping("/admin/dashboard")
@Api(tags = "主页面板接口")
public class AdminDashbordController {

    @Autowired
    LitemallUserService userService;
    @Autowired
    LitemallGoodsService goodsService;
    @Autowired
    LitemallOrderService orderService;
    @Autowired
    LitemallGoodsProductService productService;

    private static final Logger logger = LoggerFactory.getLogger(AdminDashbordController.class);

    @GetMapping("")
    @ApiOperation(value = "主页面板接口", notes = "主页面板接口")
    public Object info() {
        logger.error("进入主页面板接口--------------------");
        logger.warn("进入主页面板接口--------------------");
        logger.info("进入主页面板接口--------------------");
        logger.debug("进入主页面板接口--------------------");
        logger.trace("进入主页面板接口--------------------");

        // Log4j2 门面API
        org.apache.logging.log4j.Logger logger = LogManager.getLogger(AdminDashbordController.class);
        logger.info("log4j2 info");

        // 用户数量
        int userTotal = userService.count();
        // 商品数量
        int goodsTotal = goodsService.count();
        // 订单数量
        int orderTotal = orderService.count();
        // 货品数量
        int productTotal = productService.count();

        Map<String, Integer> data = new HashMap<>();
        data.put("userTotal", userTotal);
        data.put("goodsTotal", goodsTotal);
        data.put("orderTotal", orderTotal);
        data.put("productTotal", productTotal);

        return ResponseUtil.ok(data);
    }

}
